package main

import "fmt"

func main() {
	numbers := []int{35, 33, 42, 10, 14, 19, 27, 44}
	length := len(numbers)

	fmt.Printf("原始数据为：%v\n\n", numbers)
	//增量获取
	h := 1
	for h < length/3 {
		h = 3*h + 1
	}

	for h > 0 {
		for i := h; i < length; i++ {
			tmp := numbers[i]
			j := i
			//增量区分后分组数据对比，交换数据。
			for ; j > h-1 && numbers[j-h] >= tmp; j -= h {
				numbers[j] = numbers[j-h]
			}
			numbers[j] = tmp
		}
		fmt.Printf("增量：%d 结果：%v \n\n", h, numbers)
		//计算增量
		h = (h - 1) / 3
	}
	fmt.Printf("排序结果为：%v\n", numbers)
}
